Introduction
Developing the screen for various tables has been a boring activity. This is small step towards automating the screen generation for the aspx pages.
Currently this application can generate the aspx tags for SQL Server 2000 table.
The idea is
a. For every column in the table , A Label field is required on the screen.
b. For a natural column in the table, A text box is required on the screen.
c. If the column is not nullable , A required field validator needs to be placed on the screen.
d. For a foreign key, Usually a dropdown list is required.
d. Tab index and Max Length properties also need to be set.
To get the meta data for a table the following procedure is used. It gets the name of the column, Data Type, If it nullable, Size and if it is a foreign key.
SELECT
COLUMN_NAME,
DATA_TYPE,
IS_NULLABLE,
isnull(CHARACTER_MAXIMUM_LENGTH,0),
Now there are 4 classes in the application. Common.cs has all the common properties. Other classes for the controls are inherited from it. ToString() method is overriden to generate the aspx tag necessary for the control.
Steps to Generate the aspx code.
1. Create the stored procedures provided in your database.
2. Modify the connection information in the Form1.cs file. There are two places you have to modify the connection information . One inside GetTables() method and another inside ProcessTable(string TableName).
3. Execute the project. In the Window The combo shows the list of tables available. Enter the name of the table inside the text box and click the generate button.
4. Copy the code from the textbox below and paste inside the <form></form> tags inside your aspx page.
5. There you go.....
Currently this generates a label for every column, Text or Combo box depending on weather it is a table column or a foreign key, generates a required field validator for not nullable fields,sets the tab order and max length properties.
Let me know if there are other methods to generate aspx pages.